//
const ssr = require('./ssr/svg/namespace/SVGNamespace');

cc.Class({
    extends: cc.Component,

    properties: {
        svgNode: cc.Node,
        logView: cc.ScrollView,
    },

    onLoad () {
        cc.debug.setDisplayStats(true);
        this._testcase = cc.director.getScene().name;
        cc.Canvas.instance.node.getChildByName("Title").getComponent(cc.Label).string = "Testcase - " + this._testcase;
    },

    start () {
        this._strokeAnimateSpeed = 0.1 * 0.1;
        //
        this._writerComponent = this.svgNode.getComponent(ssr.SVG.WriterComponent);
        this._writerComponent.drawFrame();
        this._writerComponent.drawGrid();
        this._writerComponent.drawMedians();
        this._writerComponent.drawHanzi();
    },

    onEditingReturn (event) {
        let hanzi = event.textLabel.string;
        let self = this;
        this._writerComponent.load(hanzi, function (err) {
            self._writerComponent.resetHanziRender()
            if (!err) {
                self._writerComponent.drawHanzi();
            }
        });
    },

    onStrokeTestStart (event) {
        this._writerComponent.testStart();
    },

    onStrokeTestEnd (event) {
        this._writerComponent.testEnd();
    },

    onStrokeTestAccuracy (event) {
        this._writerComponent.testAccuracy = 10 + (event.progress * 50);
    },

    onHint (event) {
        this._writerComponent.hintStroke();
    },

    onHintColor (event) {
        this._writerComponent.hintColor = cc.color(255 * Math.random(), 255 * Math.random(), 255 * Math.random(), 255);
    },

    onHintSpeed (event) {
        this._writerComponent.hintSpeed = event.progress;
    },
    onCbTestStart (event, data) {
        this._addLog("onCbTestStart");
    },
    onCbTestMove (event, data) {
        this._addLog("onCbTestMove");
    },
    onCbTestEnd (event, data) {
        this._addLog("onCbTestEnd");
        this._addLog(JSON.stringify(data));
    },
    onCbTestOneStrokeStart (event, data) {
        this._addLog("onCbTestOneStrokeStart");
        this._addLog(JSON.stringify(data));
    },
    onCbTestOneStrokeEnd (event, data) {
        this._addLog("onCbTestOneStrokeEnd");
        this._addLog(JSON.stringify(data));
    },
    onCbTestOneMedianStart (event, data) {
        this._addLog("onCbTestOnMedianStart");
        this._addLog(JSON.stringify(data));
    },
    onCbTestOneMedianFinish (event, data) {
        this._addLog("onCbTestOnMedianFinish");
        this._addLog(JSON.stringify(data));
    },
    onCbTestOneMedianEnd (event, data) {
        this._addLog("onCbTestOnMedianEnd");
    },
    onCbTestHintStart (event, data) {
        this._addLog("onCbTestHintStart");
    },
    onCbTestHintEnd (event, data) {
        this._addLog("onCbTestHintEnd");
    },
    //
    _addLog (text) {
        let node = new cc.Node();
        node.anchorX = 0;
        node.anchorY = 1;
        node.color = cc.Color.BLACK;
        node.x = - 290;
        let comp = node.addComponent(cc.Label);
        comp.string = text;
        comp.fontSize = 20;
        node.parent = this.logView.content;
        //
        this.logView.scrollToBottom();
    },

    onBack () {
        cc.director.loadScene('TestList');
    }

});
